package com.xhh.nphm.web.controller.system;

import com.xhh.nphm.common.core.controller.BaseController;
import com.xhh.nphm.common.core.domain.AjaxResult;
import com.xhh.nphm.common.core.page.TableDataInfo;
import com.xhh.nphm.system.domain.TtelGetDealEty;
import com.xhh.nphm.system.domain.TwfSendBackEty;
import com.xhh.nphm.system.domain.TworkFormBaseEty;
import com.xhh.nphm.system.domain.TworkFormLogEty;
import com.xhh.nphm.system.service.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@RestController
@RequestMapping("/system/mTelWF")
public class TelWFManageController extends BaseController {
    private String prefix = "system/mTelWF";

    @Autowired
    private IWorkFormBaseService workFormBaseService;

    @Autowired
    private ITelWFManageService telWFManageService;

    @Autowired
    private ITelWFLogService telWFLogService;

    @Autowired
    private ITelWFBackService telWFBackService;

    @Autowired
    private ITelGetDealService telGetDealService;

    /**
     * 承办单位处理中 列表页面
     *
     * @param map
     * @return
     */
    @GetMapping("/rManage/sendOverList")
    public ModelAndView workform(ModelMap map) {
        return new ModelAndView(prefix+"/rManage/sendOverList");
    }

    /**
     * 承办单位处理中 列表数据
     *
     * @return
     */
    @PostMapping("/rManage/sendOverListJson")
    public TableDataInfo sendOverListJson(TworkFormBaseEty tworkFormBaseEty) {
        startPage();
        List<TworkFormBaseEty> list = telWFManageService.listSendOver(tworkFormBaseEty);
        return getDataTable(list);
    }


    /**
     * 待再次整理 列表页面
     *
     * @param map
     * @return
     */
    @GetMapping("/rManage/secondList")
    public ModelAndView secondList(ModelMap map) {
        return new ModelAndView(prefix+"/rManage/secondList");
    }

    /**
     * 根据id 进行多选删除 和单个删除
     * 待再次整理
     * @param ids
     * @return
     */
    @RequiresPermissions("mTelRcd:remove:view")
    @PostMapping("/rManage/removeSecond")
    @ResponseBody
    public AjaxResult removeSecond(String... ids) {
        return toAjax(telWFManageService.deleteByIds(ids));
    }

    /**
     * 进入重新派单页面
     * @param map
     * @return
     */
    @GetMapping("/arrangedTwfb/{id}")
    public ModelAndView arrangedTwfb(ModelMap map,@PathVariable("id") Integer pkId) {
        TworkFormBaseEty tworkFormBaseEty = workFormBaseService.getById(pkId);
        if (tworkFormBaseEty != null) {
            TtelGetDealEty telGetDealEty = telGetDealService.getById(tworkFormBaseEty.getGetDealPk());
            map.put("workFormBase", tworkFormBaseEty);
            map.put("telGetDeal",telGetDealEty);
        }
        return new ModelAndView("system/tworkform/arrangedTwfb");
    }

    /**
     * 进入结束派单页面
     * @param map
     * @return
     */
    @GetMapping("/shutdown/{id}")
    public ModelAndView shutdown(ModelMap map,@PathVariable("id") Integer pkId) {
        TworkFormBaseEty tworkFormBaseEty = workFormBaseService.getById(pkId);
        if (tworkFormBaseEty != null) {
            TtelGetDealEty telGetDealEty = telGetDealService.getById(tworkFormBaseEty.getGetDealPk());
            map.put("workFormBase", tworkFormBaseEty);
            map.put("telGetDeal",telGetDealEty);
        }
        return new ModelAndView("system/tworkform/shutdown");
    }



    /**
     * 待再次整理 列表数据
     *
     * @return
     */
    @PostMapping("/rManage/secondListJson")
    public TableDataInfo secondListJson(TworkFormBaseEty tworkFormBaseEty) {
        startPage();
        List<TworkFormBaseEty> list = telWFManageService.listSecond(tworkFormBaseEty);
        return getDataTable(list);
    }

    /**
     * 待再次整理 历史记录处理
     *
     * @param map
     * @return
     */
    @GetMapping("forShow/logList/{id}")
    public ModelAndView logList(@PathVariable("id")Integer id, ModelMap map) {
        List<TworkFormLogEty> list = telWFLogService.logList(id);
        map.put("logList",list);
        map.put("wfId",id);
        return new ModelAndView(prefix+"/forShow/logList");
    }

    /**
     * 待再次整理 调整承办部门
     *
     * @param map
     * @return
     */
    @GetMapping("forShow/sendBackList/{id}")
    public ModelAndView sendBackList(@PathVariable("id")Integer id, ModelMap map) {
        List<TwfSendBackEty> list = telWFBackService.backList(id);
        map.put("backList",list);
        return new ModelAndView(prefix+"/forShow/logList");
    }

}
